package com.tbs.parkingsaleapp.DataTool;

public class Cal
{
    public static  final int rcm_ORDER=0,rcm_PRICE=1,rcm_DISTANCE=2,rcm_LIKE=3;

    public static double[] value(int order,double price,double dis,boolean[] park,boolean[] user)
    {
        double[] mx={Order.order(order),Price.price(price),Distance.distance(dis)
                ,Like.LIKEINFO(user,park)};
        return mx;
    }

}

class Const
{
    static final int cw_like=0,cw_distance=1,cw_price=2,cw_order=3;
    static final int t_LIKE_APPLY = 0,t_ORDER_NUMBER=1,t_PRICE=2,t_DISTANCE=3;
    static final int l_UNDERGROUND=0,l_FULLLIGHT=1,l_NEARROAD=2,l_SPECIALPRICE=3,l_OPENSALE=4,l_NEARSHOP=5;
}

class Order
{
    static double map(int dis)
    {
        if(dis<=3)
            return MathTool. map(3,0,10,8,dis,false);
        else if(dis<=10)
            return MathTool.map(10,3,8,4,dis,false);
        else if(dis<=25)
            return MathTool.map(25,10,4,-4,dis,false);
        else if(dis<=50)
            return MathTool.map(50,25,-4,-8,dis,false);
        else
            return MathTool.map(200,50,-8,-10,dis,false);
    }

    static double order(int v)
    {
        double m=map(v);
        return  MathTool.logicFunctionMaker(m,0.18)*10/8.58*10;
    }
}

class Like
{
    static double[] liketomath(boolean[] a)
    {
        double[] l=new double[a.length];
        for (int i=0;i<a.length;i++)
        {
            l[i]=a[i]?1:0;
        }
        return l;
    }
    static double LIKEINFO(boolean[] userLike,boolean[] parktrait)
    {
        double[] user=liketomath(userLike);
        double[] park=liketomath(parktrait);
        return MathTool.Similarity(user,park)*10;
    }
}

class Price
{
    static double map(double dis)
    {
        if(dis<=25000)
            return MathTool. map(25000,0,10,5,dis,true);
        else if(dis<=50000)
            return MathTool.map(50000,25000,5,2,dis,true);
        else if(dis<=90000)
            return MathTool.map(90000,50000,2,-2,dis,true);
        else if(dis<=120000)
            return MathTool.map(120000,50000,-2,-8,dis,true);
        else
            return MathTool.map(300000,120000,-8,-10,dis,true);
    }
    static double price(double p)
    {
        return MathTool.logicFunctionMaker(map(p),0.23)/9.08*10*10;
    }
}


class Distance
{
    static double map(double dis)
    {
        if(dis<=5)
            return (10-dis);
        else if(dis<=15)
            return 4-(dis/15);
        else if(dis<=30)
            return 2-(dis/30)*2;
        else if(dis<=60)
            return -2-(dis/60)*1.5;
        else
            return -5-(dis/120)*2;
    }

    static double distance(double d)
    {
        return MathTool.logicFunctionMaker(map(d),0.75)*10;
    }
}

class MathTool
{
    static double map(double maxarea,double minarea,double imax,double imin,double value,boolean isless)
    {
        double area= maxarea-minarea;
        double i=imax-imin;
        double p=(value-minarea)/area;
        return isless? imax-i*(p):imin+i*(1-p);
    }
    static double dianji(double[] a,double[] b)
    {
        double p=0;
        for (int i=0;i<a.length;i++)
            p+=a[i]*b[i];
        return p;
    }
    static double modlength(double[] a)
    {
        double r=0;
        for (double p:a
        ) {
            r+=p*p;
        }
        return Math.sqrt(r);
    }
    static double Similarity( double[] a,double[] b)
    {
        double cos=dianji(a,b)/(modlength(a)*modlength(b));
        return cos;
    }
    public static double logicFunctionMaker(double t,double r)
    {
        double top=1;
        double bottom=1+(Math.exp(-r*t));

        return top/bottom;
    }

}